void ViewTopo16x16Correlator()

{
    fileData = new TFile("MergedOutput.root");
    fileMC = new TFile("./Pythia/MergedOutput.root");

    TList *listData = fileData->Get("outputPhi256");
    TList *listMC = fileMC->Get("outputPhi256");
    TList *listMCtrue = fileMC->Get("MCtrueOutputPhi256");

    //TList *listMC = fileMC->Get("outputPhi");
    //TList *listMCtrue = fileMC->Get("MCtrueOutputPhi");

    HistTopo = new TH2F("HistTopo", "N-N- correlations 3D representation pp 7 Tev", 16, -9*TMath::Pi()/16, 23*TMath::Pi()/16, 15, -0.05, 1.45); //PhiConf, EtaConf
    HistTopoCorrection = new TH2F("HistTopoCorrection", "Correction coefficient 3D representation pp 7 Tev", 16, -9*TMath::Pi()/16, 23*TMath::Pi()/16, 15, -0.05, 1.45);
    //HistTopo = new TH2F("HistTopo", "Topology of QQ Correlation pp 7 Tev Add1 config", 8, -TMath::Pi()/2, 5*TMath::Pi()/4, 4, 0, 0.8);
    //HistTopo = new TH2F("HistTopo", "Topology of QQ Correlation pp 7 Tev Add2 config", 8, -TMath::Pi()/2, 5*TMath::Pi()/4, 5, 0, 1.0);
    HistTopo->GetXaxis()->SetTitle("#phi sep");
    HistTopo->GetYaxis()->SetTitle("#eta sep");
    HistTopoCorrection->GetXaxis()->SetTitle("#phi sep");
    HistTopoCorrection->GetYaxis()->SetTitle("#eta sep");

    for (Int_t EtaConf=2; EtaConf<=14; EtaConf++)
    //for (Int_t EtaConf=1; EtaConf<=3; EtaConf++)
    //for (Int_t EtaConf=1; EtaConf<=4; EtaConf++)

        for (Int_t PhiConf=1; PhiConf<=12; PhiConf++)

        {

            THnSparseF* SparseData = (THnSparseF*) listData->FindObject(Form("fPhi1%dEta%d",PhiConf,EtaConf));
            TH1D *QfQbData = SparseData->Projection(8,"E");
            TH1D *QfData = SparseData->Projection(7,"E");
            TH1D *QbData = SparseData->Projection(6,"E");
            TH1D *QfQfData = SparseData->Projection(9,"E");

            Double_t QfQbMeanData = QfQbData->GetMean();
            Double_t QfMeanData = QfData->GetMean();
            Double_t QbMeanData = QbData->GetMean();
            Double_t QfQfMeanData = QfQfData->GetMean();

            Double_t bData=(QfQbMeanData-QfMeanData*QbMeanData)/(QfQfMeanData-QfMeanData*QfMeanData);


            THnSparseF* SparseMC= (THnSparseF*) listMC->FindObject(Form("fPhi1%dEta%d",PhiConf,EtaConf));
            TH1D *QfQbMCESD = SparseMC->Projection(8,"E");
            TH1D *QfMCESD = SparseMC->Projection(7,"E");
            TH1D *QbMCESD = SparseMC->Projection(6,"E");
            TH1D *QfQfMCESD = SparseMC->Projection(9,"E");

            Double_t QfQbMeanMCESD = QfQbMCESD->GetMean();
            Double_t QfMeanMCESD = QfMCESD->GetMean();
            Double_t QbMeanMCESD = QbMCESD->GetMean();
            Double_t QfQfMeanMCESD = QfQfMCESD->GetMean();

//            Double_t bMCESD=(QfQbMeanMCESD-QfMeanMCESD*QbMeanMCESD)/(QfQfMeanMCESD-QfMeanMCESD*QfMeanMCESD);
//            HistBMC->SetBinContent(i+1, 14, bMCESD);


            THnSparseF* SparseMCtrue = (THnSparseF*) listMCtrue->FindObject(Form("fPhi1%dEta%d",PhiConf,EtaConf));
            TH1D *QfQbMCtrue = SparseMCtrue->Projection(8,"E");
            TH1D *QfMCtrue = SparseMCtrue->Projection(7,"E");
            TH1D *QbMCtrue = SparseMCtrue->Projection(6,"E");
            TH1D *QfQfMCtrue = SparseMCtrue->Projection(9,"E");

            Double_t QfQbMeanMCtrue = QfQbMCtrue->GetMean();
            Double_t QfMeanMCtrue = QfMCtrue->GetMean();
            Double_t QbMeanMCtrue = QbMCtrue->GetMean();
            Double_t QfQfMeanMCtrue = QfQfMCtrue->GetMean();

            Double_t b_corr=((QfQbMeanData*QfQbMeanMCtrue/QfQbMeanMCESD)-(QfMeanData*QfMeanMCtrue/QfMeanMCESD)*(QbMeanData*QbMeanMCtrue/QbMeanMCESD))/((QfQfMeanData*QfQfMeanMCtrue/QfQfMeanMCESD)-(QfMeanData*QfMeanMCtrue/QfMeanMCESD)*(QfMeanData*QfMeanMCtrue/QfMeanMCESD));


            //Double_t be=qqcf->GetFunction("pol1")->GetParError(1);
            HistTopo->SetBinContent(PhiConf+4, EtaConf+1, b_corr);

        if (bData) {HistTopoCorrection->SetBinContent(PhiConf+4, EtaConf+1, b_corr/bData);} else {cout<<"error line~79";return;}

            //HistTopo->SetBinContent(PhiConf+4, EtaConf+1, bData);

        }

    for (Int_t EtaConf=0;EtaConf<=1;EtaConf++)

        for (Int_t PhiConf=3; PhiConf<=12; PhiConf++)
        {

            THnSparseF* SparseData = (THnSparseF*) listData->FindObject(Form("fPhi1%dEta%d",PhiConf,EtaConf));
            TH1D *QfQbData = SparseData->Projection(8,"E");
            TH1D *QfData = SparseData->Projection(7,"E");
            TH1D *QbData = SparseData->Projection(6,"E");
            TH1D *QfQfData = SparseData->Projection(9,"E");

            Double_t QfQbMeanData = QfQbData->GetMean();
            Double_t QfMeanData = QfData->GetMean();
            Double_t QbMeanData = QbData->GetMean();
            Double_t QfQfMeanData = QfQfData->GetMean();

            Double_t bData=(QfQbMeanData-QfMeanData*QbMeanData)/(QfQfMeanData-QfMeanData*QfMeanData);


            THnSparseF* SparseMC= (THnSparseF*) listMC->FindObject(Form("fPhi1%dEta%d",PhiConf,EtaConf));
            TH1D *QfQbMCESD = SparseMC->Projection(8,"E");
            TH1D *QfMCESD = SparseMC->Projection(7,"E");
            TH1D *QbMCESD = SparseMC->Projection(6,"E");
            TH1D *QfQfMCESD = SparseMC->Projection(9,"E");

            Double_t QfQbMeanMCESD = QfQbMCESD->GetMean();
            Double_t QfMeanMCESD = QfMCESD->GetMean();
            Double_t QbMeanMCESD = QbMCESD->GetMean();
            Double_t QfQfMeanMCESD = QfQfMCESD->GetMean();

//            Double_t bMCESD=(QfQbMeanMCESD-QfMeanMCESD*QbMeanMCESD)/(QfQfMeanMCESD-QfMeanMCESD*QfMeanMCESD);
//            HistBMC->SetBinContent(i+1, 14, bMCESD);


            THnSparseF* SparseMCtrue = (THnSparseF*) listMCtrue->FindObject(Form("fPhi1%dEta%d",PhiConf,EtaConf));
            TH1D *QfQbMCtrue = SparseMCtrue->Projection(8,"E");
            TH1D *QfMCtrue = SparseMCtrue->Projection(7,"E");
            TH1D *QbMCtrue = SparseMCtrue->Projection(6,"E");
            TH1D *QfQfMCtrue = SparseMCtrue->Projection(9,"E");

            Double_t QfQbMeanMCtrue = QfQbMCtrue->GetMean();
            Double_t QfMeanMCtrue = QfMCtrue->GetMean();
            Double_t QbMeanMCtrue = QbMCtrue->GetMean();
            Double_t QfQfMeanMCtrue = QfQfMCtrue->GetMean();

            Double_t b_corr=((QfQbMeanData*QfQbMeanMCtrue/QfQbMeanMCESD)-(QfMeanData*QfMeanMCtrue/QfMeanMCESD)*(QbMeanData*QbMeanMCtrue/QbMeanMCESD))/((QfQfMeanData*QfQfMeanMCtrue/QfQfMeanMCESD)-(QfMeanData*QfMeanMCtrue/QfMeanMCESD)*(QfMeanData*QfMeanMCtrue/QfMeanMCESD));


            //Double_t be=qqcf->GetFunction("pol1")->GetParError(1);
            HistTopo->SetBinContent(PhiConf+4, EtaConf+1, b_corr);

            if (bData) {HistTopoCorrection->SetBinContent(PhiConf+4, EtaConf+1, b_corr/bData);} else {cout<<"error line~134";return;}


        }


    for (Int_t EtaConf=2; EtaConf<=14; EtaConf++)
    //for (Int_t EtaConf=0; EtaConf<=3; EtaConf++)
    //for (Int_t EtaConf=0; EtaConf<=4; EtaConf++)

        for (Int_t PhiConf=13; PhiConf<=16; PhiConf++)

        {

            THnSparseF* SparseData = (THnSparseF*) listData->FindObject(Form("fPhi1%dEta%d",PhiConf,EtaConf));
            TH1D *QfQbData = SparseData->Projection(8,"E");
            TH1D *QfData = SparseData->Projection(7,"E");
            TH1D *QbData = SparseData->Projection(6,"E");
            TH1D *QfQfData = SparseData->Projection(9,"E");

            Double_t QfQbMeanData = QfQbData->GetMean();
            Double_t QfMeanData = QfData->GetMean();
            Double_t QbMeanData = QbData->GetMean();
            Double_t QfQfMeanData = QfQfData->GetMean();

            Double_t bData=(QfQbMeanData-QfMeanData*QbMeanData)/(QfQfMeanData-QfMeanData*QfMeanData);


            THnSparseF* SparseMC= (THnSparseF*) listMC->FindObject(Form("fPhi1%dEta%d",PhiConf,EtaConf));
            TH1D *QfQbMCESD = SparseMC->Projection(8,"E");
            TH1D *QfMCESD = SparseMC->Projection(7,"E");
            TH1D *QbMCESD = SparseMC->Projection(6,"E");
            TH1D *QfQfMCESD = SparseMC->Projection(9,"E");

            Double_t QfQbMeanMCESD = QfQbMCESD->GetMean();
            Double_t QfMeanMCESD = QfMCESD->GetMean();
            Double_t QbMeanMCESD = QbMCESD->GetMean();
            Double_t QfQfMeanMCESD = QfQfMCESD->GetMean();

//            Double_t bMCESD=(QfQbMeanMCESD-QfMeanMCESD*QbMeanMCESD)/(QfQfMeanMCESD-QfMeanMCESD*QfMeanMCESD);
//            HistBMC->SetBinContent(i+1, 14, bMCESD);


            THnSparseF* SparseMCtrue = (THnSparseF*) listMCtrue->FindObject(Form("fPhi1%dEta%d",PhiConf,EtaConf));
            TH1D *QfQbMCtrue = SparseMCtrue->Projection(8,"E");
            TH1D *QfMCtrue = SparseMCtrue->Projection(7,"E");
            TH1D *QbMCtrue = SparseMCtrue->Projection(6,"E");
            TH1D *QfQfMCtrue = SparseMCtrue->Projection(9,"E");

            Double_t QfQbMeanMCtrue = QfQbMCtrue->GetMean();
            Double_t QfMeanMCtrue = QfMCtrue->GetMean();
            Double_t QbMeanMCtrue = QbMCtrue->GetMean();
            Double_t QfQfMeanMCtrue = QfQfMCtrue->GetMean();

            Double_t b_corr=((QfQbMeanData*QfQbMeanMCtrue/QfQbMeanMCESD)-(QfMeanData*QfMeanMCtrue/QfMeanMCESD)*(QbMeanData*QbMeanMCtrue/QbMeanMCESD))/((QfQfMeanData*QfQfMeanMCtrue/QfQfMeanMCESD)-(QfMeanData*QfMeanMCtrue/QfMeanMCESD)*(QfMeanData*QfMeanMCtrue/QfMeanMCESD));


            //Double_t be=qqcf->GetFunction("pol1")->GetParError(1);
            HistTopo->SetBinContent(PhiConf-12, EtaConf+1, b_corr);

            if (bData) {HistTopoCorrection->SetBinContent(PhiConf-12, EtaConf+1, b_corr/bData);} else {cout<<"error line~194";return;}
        }


    for (Int_t EtaConf=0; EtaConf<=1; EtaConf++)

        for (Int_t PhiConf=13; PhiConf<=15; PhiConf++)

        {

            THnSparseF* SparseData = (THnSparseF*) listData->FindObject(Form("fPhi1%dEta%d",PhiConf,EtaConf));
            TH1D *QfQbData = SparseData->Projection(8,"E");
            TH1D *QfData = SparseData->Projection(7,"E");
            TH1D *QbData = SparseData->Projection(6,"E");
            TH1D *QfQfData = SparseData->Projection(9,"E");

            Double_t QfQbMeanData = QfQbData->GetMean();
            Double_t QfMeanData = QfData->GetMean();
            Double_t QbMeanData = QbData->GetMean();
            Double_t QfQfMeanData = QfQfData->GetMean();

            Double_t bData=(QfQbMeanData-QfMeanData*QbMeanData)/(QfQfMeanData-QfMeanData*QfMeanData);


            THnSparseF* SparseMC= (THnSparseF*) listMC->FindObject(Form("fPhi1%dEta%d",PhiConf,EtaConf));
            TH1D *QfQbMCESD = SparseMC->Projection(8,"E");
            TH1D *QfMCESD = SparseMC->Projection(7,"E");
            TH1D *QbMCESD = SparseMC->Projection(6,"E");
            TH1D *QfQfMCESD = SparseMC->Projection(9,"E");

            Double_t QfQbMeanMCESD = QfQbMCESD->GetMean();
            Double_t QfMeanMCESD = QfMCESD->GetMean();
            Double_t QbMeanMCESD = QbMCESD->GetMean();
            Double_t QfQfMeanMCESD = QfQfMCESD->GetMean();

//            Double_t bMCESD=(QfQbMeanMCESD-QfMeanMCESD*QbMeanMCESD)/(QfQfMeanMCESD-QfMeanMCESD*QfMeanMCESD);
//            HistBMC->SetBinContent(i+1, 14, bMCESD);


            THnSparseF* SparseMCtrue = (THnSparseF*) listMCtrue->FindObject(Form("fPhi1%dEta%d",PhiConf,EtaConf));
            TH1D *QfQbMCtrue = SparseMCtrue->Projection(8,"E");
            TH1D *QfMCtrue = SparseMCtrue->Projection(7,"E");
            TH1D *QbMCtrue = SparseMCtrue->Projection(6,"E");
            TH1D *QfQfMCtrue = SparseMCtrue->Projection(9,"E");

            Double_t QfQbMeanMCtrue = QfQbMCtrue->GetMean();
            Double_t QfMeanMCtrue = QfMCtrue->GetMean();
            Double_t QbMeanMCtrue = QbMCtrue->GetMean();
            Double_t QfQfMeanMCtrue = QfQfMCtrue->GetMean();

            Double_t b_corr=((QfQbMeanData*QfQbMeanMCtrue/QfQbMeanMCESD)-(QfMeanData*QfMeanMCtrue/QfMeanMCESD)*(QbMeanData*QbMeanMCtrue/QbMeanMCESD))/((QfQfMeanData*QfQfMeanMCtrue/QfQfMeanMCESD)-(QfMeanData*QfMeanMCtrue/QfMeanMCESD)*(QfMeanData*QfMeanMCtrue/QfMeanMCESD));


            //Double_t be=qqcf->GetFunction("pol1")->GetParError(1);
            HistTopo->SetBinContent(PhiConf-12, EtaConf+1, b_corr);

            if (bData) {HistTopoCorrection->SetBinContent(PhiConf-12, EtaConf+1, b_corr/bData);} else {cout<<"error line~194";return;}

        }


    HistTopo->SetBinContent(4,1,HistTopo->GetBinContent(5,3));
    HistTopo->SetBinContent(4,2,HistTopo->GetBinContent(5,3));
    HistTopo->SetBinContent(5,1,HistTopo->GetBinContent(5,3));
    HistTopo->SetBinContent(5,2,HistTopo->GetBinContent(5,3));
    HistTopo->SetBinContent(6,1,HistTopo->GetBinContent(5,3));
    HistTopo->SetBinContent(6,2,HistTopo->GetBinContent(5,3));


    HistTopoCorrection->SetBinContent(4,1,HistTopoCorrection->GetBinContent(5,3));
    HistTopoCorrection->SetBinContent(4,2,HistTopoCorrection->GetBinContent(5,3));
    HistTopoCorrection->SetBinContent(5,1,HistTopoCorrection->GetBinContent(5,3));
    HistTopoCorrection->SetBinContent(5,2,HistTopoCorrection->GetBinContent(5,3));
    HistTopoCorrection->SetBinContent(6,1,HistTopoCorrection->GetBinContent(5,3));
    HistTopoCorrection->SetBinContent(6,2,HistTopoCorrection->GetBinContent(5,3));


    TCanvas *c1 = new TCanvas("c1","NNabs corr coeff vs width of Eta window",50,50,800,500);
    gROOT->SetStyle("Plain");
    gStyle->SetPalette(1);
    c1->Divide(2,1,0.001,0.001);
    c1->cd(1);
    HistTopo->Draw("SURF1");
    c1->cd(2);
    HistTopoCorrection->Draw("SURF1");
    return;

}
